<template>
	<div class="businessMask" >
		<div ref="elememt" :class="windowShow ? 'businessDialog large' : 'businessDialog-hide'" style="width: calc(100vw - 95px);height: calc(100vh - 98px);margin: 5px 0px 0px 5px;">
			<div class="dialog-header">
				<span>{{ titleName }}</span>
				<span class="icon iconfont iconbiaoqianlan-guanbi" @click="hide"></span>
			</div>
			<div class="dialog-body" style="height: calc(100% - 48px);padding-top: 0px;">
				<div class="buttons-wrapper">
					<div class="businessSearchCondition">
						<label>采购类型: </label>
						<el-select class="myInput" v-model="params.type" @change="changeType">
							<el-option
									v-for="item in typeList"
									:key="item.value"
									:label="item.label"
									:value="item.value"
							></el-option>
						</el-select>
					</div>
					<div class="businessSearchCondition" style="width: 200px;">
						<label>采购方式: </label>
						<el-select class="myInput" v-model="params.way" @change="changeType">
							<el-option
									v-for="item in wayList"
									:key="item.id"
									:label="item.name"
									:value="item.id"
							></el-option>
						</el-select>
					</div>
					<div class="businessSearchCondition">
						<label>工程: </label>
						<el-input :disabled="params.type==0"  @dblclick.native="selectGc()" placeholder="请选择工程" v-model="params.gcmc"></el-input>
					</div>
					<!--<div class="businessSearchCondition">-->
						<!--<label>物资编码: </label>-->
						<!--<el-input placeholder="输入物资编码" v-model="params.partsCode"></el-input>-->
					<!--</div>-->
					<div class="businessSearchCondition">
						<label>物资名称: </label>
						<el-input placeholder="输入物资名称" v-model="params.partsName"></el-input>
					</div>
                    <div class="businessSearchCondition">
                        <label>订货编号: </label>
                        <el-input placeholder="输入采购订货编号" v-model="params.code"></el-input>
                    </div>
                    <div class="businessSearchCondition">
                        <label>仓库: </label>
                        <el-input @dblclick.native="selectWarehouse()" placeholder="请选择仓库" v-model="params.ckmc"></el-input>
                    </div>
                    <div class="businessSearches-right">
                        <span class="businessButtonCancel" @click="beforeSearch()">立即查询</span>
                        <span style="margin-left: 12px;" class="businessButtonConfirm" @click="checkGcId">确认添加</span>
                    </div>
				</div>

				<div class="manage-list">
					<div class="divtable">							
						<el-table class="businessTable"
							:height="tableHeight"
					      :data="tableData"
					      style="width: 100%"
                        ref="multipleTable">
                            <el-table-column
                                    type="selection"
                                    width="55">
                            </el-table-column>
                            <el-table-column
                                    prop="gcbh"
                                    label="工程编号"
                                    width="130"
                                    :show-overflow-tooltip="true"
                                    v-if="showEngineeringInfo">
                            </el-table-column>
                            <el-table-column
                                    prop="gcmc"
                                    label="工程名称"
                                    width="130"
                                    :show-overflow-tooltip="true"
                                    v-if="showEngineeringInfo">
                            </el-table-column>
                            <el-table-column
                                    prop="code"
                                    label="采购订货编号"
                                    width="300"
                                    :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column
                                    prop="partsCode"
                                    label="物资编码"
                                    :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column
                                    prop="partsName"
                                    label="物资名称"
                                    :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column
                                    prop="partsType"
                                    label="规格型号"
                                    :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column
                                    prop="partsUnit"
                                    label="单位"
                                    width="50px">
                            </el-table-column>
                            <el-table-column
                                    prop="orderNum"
                                    label="申请数量"
                                    width="130"
                                    class-name="orderNumStyle">
                                <template slot-scope="scope">
                                    <el-input-number :step="1" v-model="scope.row.orderNum" @change="handleNumChange" :min="0" :max="tableDataCopy[scope.$index].orderNum"  size="mini"></el-input-number>
                                </template>
                            </el-table-column>
                            <el-table-column
                                    prop="typeName"
                                    label="采购类型"
                                    :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column
                                    prop="wayName"
                                    label="采购方式"
                                    :show-overflow-tooltip="true">
                            </el-table-column>
					   </el-table>
					</div>
                    <div class="dialog-header" style="background-color: #fff">
                        <span>入库信息</span>
                    </div>
                    <el-row>
                        <div class="buttons-wrapper">
                            <div class=" businessSearches-left">
                                <div class="businessSearchCondition">
                                    <label>工程名称: </label>
                                    <el-input placeholder="输入工程名称" :disabled="true" v-model="formData.gcmc"></el-input>
                                </div>
                                <!--<div class="businessSearchCondition">-->
                                    <!--<label>保管员: </label>-->
                                    <!--<el-input @dblclick.native="selectKeeper()" placeholder="保管员" v-model="formData.keeperName"></el-input>-->
                                <!--</div>-->
                                <div class="businessSearchCondition">
                                    <label>采购类型: </label>
                                    <el-input placeholder="采购类型" :disabled="true" v-model="typeList[formData.type].label"></el-input>
                                </div>
                                <div class="businessSearchCondition">
                                    <label>采购方式: </label>
                                    <el-input placeholder="采购方式" :disabled="true" v-model="formData.wayString"></el-input>
                                </div>
                                <div class="businessSearchCondition">
                                    <label>备注: </label>
                                    <el-input placeholder="输入备注" v-model="formData.remark"></el-input>
                                </div>
                            </div>
                            <div class="businessSearches-right">
                                <span style="margin-left: 12px;" class="businessButtonConfirm" @click="submitFormdata()">保存</span>
                            </div>
                        </div>
                        <el-col :span="15">
                            <div class="divtable">
                                <el-table class="businessTable"
                                          :height="tableHeight"
                                          :data="wzList"
                                          style="width: 100%"
                                            @row-click="showDetailList">
                                    <el-table-column
                                            type="selection"
                                            width="55">
                                    </el-table-column>
                                    <el-table-column
                                            prop="partsCode"
                                            label="物资编码"
                                            :show-overflow-tooltip="true">
                                    </el-table-column>
                                    <el-table-column
                                            prop="partsName"
                                            label="物资名称"
                                            :show-overflow-tooltip="true">
                                    </el-table-column>
                                    <el-table-column
                                            prop="partsType"
                                            label="规格型号"
                                            :show-overflow-tooltip="true">
                                    </el-table-column>
                                    <el-table-column
                                            prop="partsUnit"
                                            label="单位">
                                    </el-table-column>
                                    <el-table-column
                                            prop="num"
                                            label="订货数量"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="price"
                                            label="单价"
                                            :show-overflow-tooltip="true"
                                            width="130"
                                            class-name="orderNumStyle">
                                        <template slot-scope="scope">
                                            <el-input-number :step="0.01" step-strictly v-model="scope.row.price" :min="0.01" size="mini"></el-input-number>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="操作">
                                        <template slot-scope="scope">
                                            <i class="el-icon-delete" @click.stop="removeDetail(scope.$index, scope.row)"></i>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </el-col>
                        <el-col :span="8" :offset="1">
                            <div class="divtable" >
                                <el-table class="businessTable"
                                          :height="tableHeight"
                                          :data="detailList"
                                          style="width: 100%">
                                    <el-table-column
                                            type="selection"
                                            width="55">
                                    </el-table-column>
                                    <el-table-column
                                            type="index"
                                            label="序号"
                                            :show-overflow-tooltip="true">
                                    </el-table-column>
                                    <el-table-column
                                            prop="code"
                                            label="采购申请编号"
                                            :show-overflow-tooltip="true">
                                    </el-table-column>
                                    <el-table-column
                                            prop="inNum"
                                            label="订货数量"
                                    >
                                    </el-table-column>
                                    <el-table-column label="操作">
                                        <template slot-scope="scope">
                                            <i class="el-icon-delete" @click.stop="removeWzDetail(scope.$index, scope.row)"></i>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </el-col>
                    </el-row>
				</div>
			</div>
		</div>
        <!-- 工程选择弹窗 -->
        <template-window
                v-if="engineeringWindowShow"
                :params="engineeringWindowParams"
                ref="engineeringWindow"
                @confirm="getWindowData"
                @cancel="handelEngineeringWindow"
        ></template-window>
        <!-- 保管员弹窗 -->
        <OrganizationTree
                v-if="keeperShow"
                :dialogTitle="keeperTitle"
                :type="2"
                :dialogShow="1"
                :checkBoxShow="2"
                :propsParam="keeperParam"
                @getCheckedRoles="getKeeperData"
                @treeCancel="keeperHide"
        />
        <!-- 仓库弹窗 -->
        <template-window
                v-if="warehouseWindowShow"
                :params="warehouseWindowParams"
                ref="warehouseWindow"
                @confirm="getWarehouseWindowData"
                @cancel="handelWarehouseWindow"
        ></template-window>
	</div>
</template>
<script>
    import TemplateWindow from "@/system/pages/customPage/templateWindow";
    import OrganizationTree from "@/system/components/organizationTree";
	import { wayListFromDict,
        getPartsInDetailList,
        savePartsOrder} from "@/business/api/partsIn.js";
	export default {
		name: "partsOrder",
        components:{
            TemplateWindow,
            OrganizationTree
        },
		props: {
			titleName:{
				default:"新增入库"
			},
            relatedWinParams:{
            }
		},
		data() {
			return {
				windowShow:true,
				params:{
                    type:0,
                    way:0,
                    start:0,
                    limit:0,
                    gcbh:"",
                    gcmc:"",
                    partsCode:"",
                    partsName:"",
                    code:"",
                    gcid:"",
                    code:"",
                    ckId:0,
                    ckmc:""
				},
				totalCount: 0,
      			pageIndex: 1,
      			pageSize: 10,	
      			originPageSize:null,
      			tableData: [],
                tableDataCopy:[],
		        tableHeight:200,
                typeList:[{
				    value:0,
					label:"库存"
				},{
                    value:1,
                    label:"一收一付"
                }],
                wayList:[],
                orderNumStyle:{
				    padding:"none !important"
                },
                wzList:[],
                selectGcId:0,
                detailList:[],
                selectDetailIndex:-1,
                haveChanged:false,
                formData:{
                    funcId:0,
                    gcId:0,
                    type:0,
                    way:0,
                    bgy:0,
                    remark:"",
                    fillDeptId:0,
                    partsOrderSubList:[],
                    bgyName:"",
                    wayString:"",
                    ckmc:"",
                    ckId:0
                },
                engineeringWindowShow: false,
                engineeringWindowParams: {
                    id: "683", // 页面 id
                    menuCode: "JY_PS_GCXX", // 页面编码
                    multipleChoice: "0", // 0-单选 1-多选
                    dialogTitle: "工程管理", // 标题
                    deptId: 0, // 部门 ID
                    cellParams: {}, // 按钮传给表单参数
                    businessInfo: {}, // 按钮传给表单后台参数
                    serverParams: {}, // 按钮传给后台参数
                    params:{
                        userId:0
                    }
                },
                userInfo:{},
                keeperShow: false,
                keeperTitle:"人员选择",
                keeperParam: {"userFlag":true,"parentId":0},
                showEngineeringInfo:false,
                warehouseWindowShow: false,
                warehouseWindowParams: {
                    id: "1263", // 页面 id
                    menuCode: "JY_MM_CKGL", // 页面编码
                    multipleChoice: "0", // 0-单选 1-多选
                    dialogTitle: "仓库管理", // 标题
                    deptId: 0, // 部门 ID
                    cellParams: {}, // 按钮传给表单参数
                    businessInfo: {}, // 按钮传给表单后台参数
                    serverParams: {}, // 按钮传给后台参数
                    params:{
                    }
                },
                showWarehouseInfo:false,
                lastWarehouseId:0
			};
		},
		created:function(){
		    this.getWayList(581,0);
            this.formData.fillDeptId = this.relatedWinParams.deptId;
            this.formData.funcId = this.relatedWinParams.funcId;
            this.warehouseWindowParams.deptId = this.relatedWinParams.deptId;
            this.userInfo = this.$store.state.user.info;
		},
		mounted: function() {
			this.originPageSize = this.pageSize;
		},
		methods: {
            //显示仓库选择弹框
            selectWarehouse(){
                this.warehouseWindowParams.deptId = this.userInfo.deptId;
                this.warehouseWindowParams.params.userId =  this.userInfo.id;
                this.warehouseWindowShow = true;
            },
            //显示工程选择弹框
            selectGc(){
                if(this.params.type==1){
                    this.engineeringWindowParams.deptId = this.userInfo.deptId;
                    this.engineeringWindowParams.params.userId =  this.userInfo.id;
                    this.engineeringWindowShow = true;
                }
            },
            //显示保管员选择弹框
            selectKeeper(){
                // this.supplierWindowParams.deptId = this.userInfo.deptId;
                this.keeperShow = true;
            },
			hide(){
				this.windowShow = false;
				setTimeout(() => {
					this.$emit("close");
				}, 400);
			},
			handleCurrentChange(e) {
		      this.pageIndex = e;
		      this.search();
		    },
		    // 每页显示页码
		    handleSizeChange(e) {
		      this.pageSize = e;
		      this.search();
		    },
            beforeSearch(){
                if(this.params.ckId == 0 ){
                    this.message("请选择仓库",3)
                    return;
                }
                if(this.formData.ckId!=0 && this.formData.ckId != this.params.ckId){
                    this.haveChanged = true;
                }
			   if(this.haveChanged && this.wzList.length>0){
                   this.messageBox("切换采购类型或者采购方式会清空已选物资，确认搜索吗？").then((res) => {
                       if (res.action) {
                           this.search();
                           this.haveChanged = false;
                           this.wzList = [];
                           if(this.params.type == 1){
                               this.showEngineeringInfo = true;
                           }else{
                               this.showEngineeringInfo = false;
                               this.params.gcid = 0;
                               this.params.gcmc = "";
                           }
                       }
                   });
               }else{
			       if(this.params.type == 1 && this.params.gcid == 0){
			           this.message("请选择工程",3)
                   }else{
                       if(this.params.type == 1){
                           this.showEngineeringInfo = true;
                       }else{
                           this.showEngineeringInfo = false;
                           this.params.gcid = 0;
                           this.params.gcmc = "";
                       }
                       this.search();
                   }
               }
            },
		    search(){
                this.haveChanged = false;
                this.tableData = [];
                this.tableDataCopy = [];
                getPartsInDetailList(this.params).then((res) => {
					if (res.success) {
                    let info = res.info;
                    if(info.length>0){
                        //如果原来有选中数据，则查数据时，减去相同数据的数量
                        if(this.wzList.length>0){
                            for(let i=0;i< info.length;i++){
                                for(let j=0;j< this.wzList.length;j++){
                                    if(info[i].partsId == this.wzList[j].partsId){
                                        for(let k = 0 ; k < this.wzList[j].partsOrderInList.length;k++){
                                            if(info[i].applyId == this.wzList[j].partsOrderInList[k].applyId && info[i].applySubId == this.wzList[j].partsOrderInList[k].applySubId){
                                                info[i].orderNum -= this.wzList[j].partsOrderInList[k].inNum;
                                            }
                                        }
                                    }
                                }
                            }
                            this.tableData = info;
                            if(info.length>0){
                                for(let i=0;i<res.info.length;i++){
                                    this.tableDataCopy.push({
                                        orderNum:res.info[i].orderNum,
                                        detailId:res.info[i].orderSubId
                                    })
                                }
                            }
                        }else{
                            this.tableData = info;
                            if(info.length>0){
                                for(let i=0;i<res.info.length;i++){
                                    this.tableDataCopy.push({
                                        orderNum:res.info[i].orderNum,
                                        detailId:res.info[i].orderSubId
                                    })
                                }
                            }
                        }
                    }
					} else this.message(res.msg, 3);
				});
		    },
			getWayList(id,type){
                wayListFromDict({ pid: id }).then((res) => {
					if (res.success) {
                    		this.wayList = res.info;
							if(this.wayList && this.wayList.length>0){
								this.params.way = this.wayList[0].id;
                            }
						} else this.message(res.msg, 3);
					});
				},
            handleNumChange(value){

            },
            checkGcId(){
                if(this.$refs.multipleTable.selection.length>0){
                    if(this.params.type == 1){
                        let selection = this.$refs.multipleTable.selection;
                        if(selection.length > 0 ){
                            let flag = false;
                            for(let i = 0 ; i < selection.length; i ++){
                                if(this.wzList.length == 0 && this.selectGcId == 0 ){
                                    this.selectGcId = selection[0].gcId;
                                } else if(selection[i].gcId != this.selectGcId){
                                    this.message('不能选择多个工程的物资', 3);
                                    flag = true;
                                    break;
                                }
                            }
                            if(!flag){
                                //设置选择的工程
                                this.formData.gcId = selection[0].gcId;
                                this.formData.gcmc = selection[0].gcmc;
                                this.toggleSelection();
                            }
                        }
                    }else{
                        this.toggleSelection();
                    }
                }

            },
            toggleSelection(){
                let wzList = [];
                let selection = this.$refs.multipleTable.selection;
                //设置采购方式
                for(let i=0;i<this.wayList.length;i++){
                    if(this.wayList[i].id == this.params.way){
                        this.formData.wayString = this.wayList[i].name;
                    }
                }
                //设置保管员
                this.formData.bgy = selection[0].bgy;
                //设置供应商
                this.formData.supplier = selection[0].gys;
                //设置仓库信息
                this.formData.ckId = this.params.ckId;
                this.formData.ckmc = this.params.ckmc;
                this.formData.way = this.params.way;
                //设置采购类型
                this.formData.type = this.params.type;
                //如果之前没有选中的物资，则将现在选中的物资存入list
			    if(this.wzList.length == 0){
                    for( let i = 0 ; i < selection.length; i++){
                        if(selection[i].orderNum != 0 ){
                            //判断是否有一样的物资
                            if(wzList.length>0){
                                let flag = false;
                                for( let j = 0 ; j < wzList.length; j++){
                                    if(wzList[j].partsId == selection[i].partsId){
                                        //如果有，则叠加
                                        wzList[j].num += selection[i].orderNum;
                                        let detailFlag = false;
                                        if( wzList[j].partsOrderInList.length > 0){
                                            for(let k=0;k< wzList[j].partsOrderInList.length;k++){
                                                if(wzList[j].partsOrderInList[k].orderId == selection[i].orderId && wzList[j].partsOrderInList[k].partsId == selection[i].partsId&& wzList[j].partsApplyOrderList[k].orderSubId == selection[i].orderSubId){
                                                    detailFlag = true;
                                                    wzList[j].partsOrderInList[k].inNum += selection[i].orderNum;
                                                }
                                            }
                                        }
                                        if(!detailFlag){
                                            wzList[j].partsOrderInList.push({
                                                //采购申请id
                                                orderId:selection[i].orderId,
                                                //采购申请明细id
                                                orderSubId:selection[i].orderSubId,
                                                //物料id
                                                partsId:selection[i].partsId,
                                                //申请订货数量
                                                inNum:selection[i].orderNum,
                                                code:selection[i].code
                                            })
                                        }
                                        flag = true;
                                        this.changeMaxNum(selection[i].orderSubId,selection[i].orderNum);
                                        break;
                                    }
                                }
                                if(!flag){
                                    //如果没有，则新增
                                    let wzListDetail = {
                                        //物料id
                                        partsId:selection[i].partsId,
                                        //单价
                                        price:1.00,
                                        //订货数量
                                        num:selection[i].orderNum,
                                        partsCode:selection[i].partsCode,
                                        partsName:selection[i].partsName,
                                        partsType:selection[i].partsType,
                                        partsUnit:selection[i].partsUnit
                                    }
                                    wzListDetail.partsOrderInList=[{
                                        //采购申请id
                                        orderId:selection[i].orderId,
                                        //采购申请明细id
                                        orderSubId:selection[i].orderSubId,
                                        //物料id
                                        partsId:selection[i].partsId,
                                        //申请订货数量
                                        inNum:selection[i].orderNum,
                                        code:selection[i].code
                                    }]
                                    wzList.push(wzListDetail)
                                    this.changeMaxNum(selection[i].orderSubId,selection[i].orderNum);
                                }
                            } else {
                                //如果没有，则新增
                                let wzListDetail = {
                                    //物料id
                                    partsId:selection[i].partsId,
                                    //单价
                                    price:1.00,
                                    //订货数量
                                    num:selection[i].orderNum,
                                    partsCode:selection[i].partsCode,
                                    partsName:selection[i].partsName,
                                    partsType:selection[i].partsType,
                                    partsUnit:selection[i].partsUnit
                                }
                                wzListDetail.partsOrderInList = [{
                                    //采购申请id
                                    orderId:selection[i].orderId,
                                    //采购申请明细id
                                    orderSubId:selection[i].orderSubId,
                                    //物料id
                                    partsId:selection[i].partsId,
                                    //申请订货数量
                                    inNum:selection[i].orderNum,
                                    code:selection[i].code
                                }]
                                this.changeMaxNum(selection[i].orderSubId,selection[i].orderNum);
                                wzList.push(wzListDetail)
                            }
                        }
                    }
                }else{
                    wzList = this.wzList;
			        let selection = this.$refs.multipleTable.selection;
			        for( let i = 0 ; i < selection.length; i++){
                        if(selection[i].orderNum != 0 ){
                            let flag = false;
                            for( let j = 0 ; j < wzList.length; j++){
                                //如果是同一个物资，则累加
                                if(selection[i].partsId == wzList[j].partsId){
                                    wzList[j].num += selection[i].orderNum;
                                    let detailFlag = false;
                                    if( wzList[j].partsOrderInList.length > 0){
                                        for(let k=0;k< wzList[j].partsOrderInList.length;k++){
                                            if(wzList[j].partsOrderInList[k].orderId == selection[i].orderId && wzList[j].partsOrderInList[k].partsId == selection[i].partsId&& wzList[j].partsOrderInList[k].orderSubId == selection[i].orderSubId){
                                                detailFlag = true;
                                                wzList[j].partsOrderInList[k].inNum += selection[i].orderNum;
                                            }
                                        }
                                    }
                                    if(!detailFlag){
                                        wzList[j].partsOrderInList.push({
                                            //采购申请id
                                            orderId:selection[i].orderId,
                                            //采购申请明细id
                                            orderSubId:selection[i].orderSubId,
                                            //物料id
                                            partsId:selection[i].partsId,
                                            //申请订货数量
                                            inNum:selection[i].orderNum,
                                            code:selection[i].code
                                        })
                                    }

                                    flag = true;
                                    this.changeMaxNum(selection[i].orderSubId,selection[i].orderNum);
                                    break;
                                }
                            }
                            if(!flag){
                                //如果没有，则新增
                                let wzListDetail = {
                                    //物料id
                                    partsId:selection[i].partsId,
                                    //单价
                                    price:1.00,
                                    //订货数量
                                    num:selection[i].orderNum,
                                    partsCode:selection[i].partsCode,
                                    partsName:selection[i].partsName,
                                    partsType:selection[i].partsType,
                                    partsUnit:selection[i].partsUnit
                                }
                                wzListDetail.partsOrderInList = [{
                                    //采购申请id
                                    orderId:selection[i].orderId,
                                    //采购申请明细id
                                    orderSubId:selection[i].orderSubId,
                                    //物料id
                                    partsId:selection[i].partsId,
                                    //申请订货数量
                                    inNum:selection[i].orderNum,
                                    code:selection[i].code
                                }]
                                this.changeMaxNum(selection[i].orderSubId,selection[i].orderNum);
                                wzList.push(wzListDetail)
                            }
                        }
                    }
                }
                this.wzList = wzList;
            },
            changeMaxNum(val,dNum){
                console.log( this.tableDataCopy)
                console.log( this.tableData)
                //修改最大可选数量
                for(let j=0 ; j< this.tableDataCopy.length;j++){
                    if(this.tableDataCopy[j].detailId == val){
                        this.tableDataCopy[j].orderNum -= dNum ;
                        console.log( this.tableDataCopy[j])
                        console.log( this.tableData[j])
                        this.tableData[j].orderNum = this.tableDataCopy[j].orderNum ;
                    }
                }
            },
            showDetailList(row, column, event){
                this.selectDetailIndex = column;
                this.detailList = row.partsOrderInList;
            },
            removeDetail(index,row){
                //移除已选数据，将上方可选最大值加回去
                this.wzList.splice(index,1);
                for(let i = 0; i < row.partsOrderInList.length;i++){
                    for(let j = 0 ; j < this.tableDataCopy.length;j++){
                        if(row.partsOrderInList[i].orderSubId == this.tableDataCopy[j].detailId){
                            this.tableDataCopy[j].orderNum += row.partsOrderInList[i].inNum;
                        }
                    }
                    for(let j = 0 ; j < this.tableData.length;j++){
                        if(row.partsOrderInList[i].orderSubId == this.tableData[j].orderSubId){
                            this.tableData[j].orderNum += row.partsOrderInList[i].inNum;
                        }
                    }
                }
                //隐藏右侧列表
                this.selectDetailIndex = -1;
                this.detailList = [];
            },
            removeWzDetail(index,row){
                for(let j = 0 ; j < this.tableDataCopy.length;j++){
                    if(row.orderSubId == this.tableDataCopy[j].detailId){
                        this.tableDataCopy[j].orderNum += row.inNum;
                    }
                }s
                for(let j = 0 ; j < this.tableData.length;j++){
                    if(row.orderSubId == this.tableData[j].orderSubId){
                        this.tableData[j].orderNum += row.inNum;
                    }
                }
                //移除已选数据，将上方可选最大值加回去
                for(let i = 0; i < this.wzList.length;i++){
                    for(let j = 0 ; j<this.wzList[i].partsOrderInList.length;j++){
                        if(this.wzList[i].partsOrderInList[j] != undefined &&this.wzList[i].partsOrderInList[j].orderId == row.orderId && this.wzList[i].partsOrderInList[j].orderSubId == row.orderSubId && this.wzList[i].partsOrderInList[j].code == row.code ){
                            this.wzList[i].partsOrderInList.splice(index,1);
                            this.wzList[i].num -= row.inNum;
                            if(this.wzList[i].num==0){
                                this.wzList.splice(i,1)
                            }
                            return
                        }
                    }
                }
            },
            changeType(val){
			    this.haveChanged = true;
            },
            getWindowData(e){
                this.params.gcid = e[0].GC_ID;
                this.params.gcmc = e[0].GCMC;
                this.engineeringWindowShow = false;
            },
            handelEngineeringWindow(){
                this.engineeringWindowShow = false;
            },
            getKeeperData(e){
                this.formData.bgy = e[0].id;
                this.formData.keeperName = e[0].name;
                this.keeperShow = false;
            },
            keeperHide(){
                this.keeperShow = false;
            },
            getWarehouseWindowData(e){
                this.params.ckId = e[0].CK_ID;
                this.params.ckmc = e[0].CKMC;
                this.warehouseWindowShow = false;
            },
            handelWarehouseWindow(){
                this.warehouseWindowShow = false;
            },
            submitFormdata(){
               //判断数据
               //  if(this.formData.bgy==0){
               //      this.message("请选择保管员",3);
               //      return;
               //  } else
                if(this.wzList.length == 0){
                    this.message("请选择物资",3);
                    return;
                }
                //设置deptId
                // this.formData.fillDeptId = this.$store.state.user.info.deptId;
                //提交数据
                this.formData.partsInSubList = this.wzList
                savePartsOrder(JSON.stringify(this.formData)).then((res) => {
                    if (res.success) {
                    this.message(res.msg, 1);
                    this.hide();
                } else this.message(res.msg, 3);
            });

            }
		},

	};
</script>
<style scoped>
	.manage-list {
		height: calc(100% - 72px);
		border-radius: 6px;
		display: flex;
		flex-direction: column;
		border-radius: 6px;
	}
	.businessSearchCondition{
		width: 150px;
		margin-right: 10px;
	}
	
	.divtable{
		width: 100%;
		height: calc(50% - 24px);
	}
    .orderNumStyle .cell{
        height: auto !important;
    }
	
	
</style>
<style>
    .businessTable .el-table__body tr .orderNumStyle .cell{
        height: auto !important;
    }
</style>